<section class="content-header">
    <h1>
        商城管理
        <small></small>
    </h1>
</section>

<!-- Main content -->
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <!-- general form elements -->
            <div class="box box-default">
                <div class="box-header with-border">
                    <h3 class="box-title">商品搜索</h3>
                </div>
                <!-- form start -->
                <form class="form-horizontal" action="{:U('Admin/Shop/productSearch')}" method="post">
                    <div class="box-body">
                        <div class="form-group">
                            <label class="col-sm-1 control-label">商品ID</label>

                            <div class="col-sm-3">
                                <input class="form-control" name="id" placeholder="" value="{$productPost.id}"
                                       type="text">
                            </div>

                            <label class="col-sm-1 control-label">商品名称</label>

                            <div class="col-sm-3">
                                <input class="form-control" name="name" placeholder="" value="{$productPost.name}"
                                       type="text">
                            </div>

                            <label class="col-sm-1 control-label">推荐状态</label>

                            <div class="col-sm-3">
                                <select name="recommend" class="form-control">
                                    <option value="-10">不选择推荐状态</option>
                                    <option value="0">正常</option>
                                    <option value="1">推荐</option>
                                </select>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-1 control-label">商品状态</label>

                            <div class="col-sm-3">
                                <select name="status" class="form-control">
                                    <option value="-10">不选择商品状态</option>
                                    <option value="0">下架</option>
                                    <option value="1">出售</option>
                                </select>
                            </div>

                            <label class="col-sm-1 control-label">时间范围</label>

                            <div class="col-sm-7">
                                <div class="input-group">
                                    <div class="input-group-addon">
                                        <i class="fa fa-clock-o"></i>
                                    </div>
                                    <input type="text" class="form-control pull-right" name="timeRange"
                                           id="reservationtime" value="{$productPost.timeRange}">
                                </div>
                            </div>
                        </div>
                    </div>
                    <!-- /.box-body -->

                    <div class="box-footer">
                        <div class="col-sm-2">
                            <button type="submit" class="btn btn-block btn-danger">开始搜索</button>
                        </div>
                    </div>
                </form>
            </div>
            <!-- /.box -->
        </div>
        <!--/.col (right) -->
    </div>

    <div class="row">
        <!-- /.col -->
        <div class="col-md-12">
            <div class="box box-danger">
                <div class="box-header with-border">
                    <h3 class="box-title">商品管理</h3>
                    <!-- /.box-tools -->
                </div>
                <!-- /.box-header -->
                <div class="box-body no-padding">
                    <div class="mailbox-controls">
                        <div class="btn-group">
                            <a href="{:U('Admin/Shop/addProduct')}" class="btn btn-danger ">
                                新增商品
                            </a>
                        </div>
                        <div class="btn-group">
                            <a href="{:U('Admin/Shop/exportProduct')}" target="_blank" class="btn btn-danger ">
                                导出全部商品
                            </a>
                        </div>
                        <!-- /.btn-group -->
                    </div>
                    <div class="table-responsive" style="overflow-x: visible;">
                        <table class="table table-hover">
                            <tbody>
                            <tr>
                                <th class="hidden-xs">
                                    <label><input onchange="checkAll()" type="checkbox" value=""></label>
                                </th>
                                <th>ID</th>
                                <th>商品名称</th>
                                <th>链接</th>
                                <th>图片</th>
                                <th>价格</th>
                                <th>积分</th>
                                <th>库存</th>
                                <th>商品菜单</th>
                                <th>推荐状态</th>
                                <th>出售状态</th>
                                <th>时间</th>
                                <th>备注</th>
                                <th>操作</th>
                            </tr>
                            <volist name="productList" id="product">
                                <tr>
                                    <td class="hidden-xs">
                                        <label><input name="checkbox" class="check" type="checkbox"
                                                      value="{$product.id}"></label>
                                    </td>
                                    <td>{$product.id}</td>
                                    <td>{$product.name}</td>
                                    <td>
                                        <div class="btn-group" style="margin: 0px">
                                            <button class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                                链接<span class="caret"></span></button>
                                            <div class="dropdown-menu" style="padding: 10px;max-width: none;">
                                                {$url}{:U('App/Shop/product' , array('id'=>$product['id']))}
                                            </div>
                                        </div>
                                    </td>
                                    <td>
                                        <div class="btn-group" style="margin: 0px">
                                            <button class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                                图片<span class="caret"></span></button>
                                            <div class="dropdown-menu">
                                                <img style="height: 200px"
                                                     src="__PUBLIC__/Uploads/{$product.savepath}{$product.savename}">
                                            </div>
                                        </div>
                                    </td>
                                    <td>{$product.price}</td>
                                    <td>{$product.score}</td>
                                    <td>{$product.store}</td>
                                    <td>{$product.menu_name}</td>
                                    <td>
                                        <if condition="$product.recommend eq 1"><span
                                                class="label label-success">推荐</span>
                                            <else/>
                                            正常
                                        </if>
                                    </td>
                                    <td>
                                        <if condition="$product.status eq 1">
                                            <span class="label label-success">出售</span>
                                            <elseif condition="$product.status eq -1"/>
                                            下架
                                            <else/>
                                            <span class="label label-default">售罄</span>
                                        </if>
                                    </td>
                                    <td>{$product.time}</td>
                                    <td>{$product.remark}</td>
                                    <td class="table-action">
                                        <if condition="$product.status eq -1">
                                            <a href="{:U('Admin/Shop/updateProduct',array('id'=>$product['id'],'status'=>1))}">出售</a>
                                            <a href="{:U('Admin/Shop/updateProduct',array('id'=>$product['id'] , 'status'=>0))}">售罄</a>
                                            <elseif condition="$product.status eq 1"/>
                                            <a href="{:U('Admin/Shop/updateProduct',array('id'=>$product['id'] , 'status'=>-1))}">下架</a>
                                            <a href="{:U('Admin/Shop/updateProduct',array('id'=>$product['id'] , 'status'=>0))}">售罄</a>
                                            <else/>
                                            <a href="{:U('Admin/Shop/updateProduct',array('id'=>$product['id'] , 'status'=>1))}">出售</a>
                                            <a href="{:U('Admin/Shop/updateProduct',array('id'=>$product['id'] , 'status'=>-1))}">下架</a>
                                        </if>

                                        <a href="{:U('Admin/Shop/modifyProduct',array('id'=>$product['id']))}">修改</a><a
                                            href="{:U('Admin/Shop/delProduct',array('id'=>$product['id']))}">删除</a></td>
                                </tr>
                            </volist>
                            </tbody>
                        </table>
                        <div class="box-footer no-padding">
                            <div class="mailbox-controls">
                                <div class="btn-group">
                                    <button type="button" class="btn btn-danger"
                                            onclick="batchUrl('{:U(\'Admin/Shop/delProduct\')}')">全部删除
                                    </button>
                                </div>

                                <div class="btn-group">
                                    <button type="button" class="btn btn-danger"
                                            onclick="batchUrl('{:U(\'Admin/Shop/updateProduct\',array(\'status\'=>1))}')">
                                        出售
                                    </button>
                                </div>

                                <div class="btn-group">
                                    <button type="button" class="btn btn-danger"
                                            onclick="batchUrl('{:U(\'Admin/Shop/updateProduct\',array(\'status\'=>-1))}')">
                                        下架
                                    </button>
                                </div>

                                <div class="btn-group">
                                    <button type="button" class="btn btn-danger"
                                            onclick="batchUrl('{:U(\'Admin/Shop/updateProduct\',array(\'recommend\'=>1))}')">
                                        推荐
                                    </button>
                                </div>

                                <div class="btn-group">
                                    <button type="button" class="btn btn-danger"
                                            onclick="batchUrl('{:U(\'Admin/Shop/updateProduct\',array(\'recommend\'=>0))}')">
                                        取消推荐
                                    </button>
                                </div>
                                <div class="pull-right">
                                    {$page}
                                    <!-- /.btn-group -->
                                </div>
                            </div>
                            <!-- /.btn-group -->
                            <!-- /.pull-right -->
                        </div>
                    </div>
                </div>
                <!-- /.mail-box-messages -->
            </div>
        </div>
        <!-- /. box -->
    </div>
    <!-- /.col -->
    </div>
</section>
<script type="text/javascript">
    $(function () {
        $('#reservationtime').daterangepicker({
            timePicker: true,
            timePickerIncrement: 30,
            format: 'YYYY-MM-DD h:mm:ss',
            separator: ' --- ',
        });
        if ('{$productPost}') {
            $('select[name="recommend"]').val('{$productPost.recommend}');
            $('select[name="status"]').val('{$productPost.status}');
        }
    });
</script>